package controllers

import (
	"fmt"
	"log"

	"github.com/tealeg/xlsx"
)

//解析xlsx文件
func parseXlsxFile(fileName string) ([]map[string]interface{}, error) {
	var mResult []map[string]interface{}

	xlFile, err := xlsx.OpenFile(fileName)
	if err != nil {
		log.Println(err)
		return mResult, err
	}
	for _, sheet := range xlFile.Sheets {
		for _, row := range sheet.Rows {
			mVue := make(map[string]interface{}, 0)
			for index, cell := range row.Cells {
				sStr := cell.String()
				if index == 0 {
					mVue["name"] = sStr
				} else if index == 1 {
					mVue["accont"] = sStr
				} else if index == 2 {
					mVue["pwd"] = sStr
				} else if index == 3 {
					mVue["proc"] = sStr
				}
			}
			fmt.Println(mVue)
			mResult = append(mResult, mVue)
		}
	}
	return mResult, nil
}
